package com.findtech.threePomelos.base;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;

import com.avos.avoscloud.AVAnalytics;
import com.findtech.threePomelos.R;
import com.findtech.threePomelos.activity.HomeActivity;
import com.findtech.threePomelos.activity.LaunchActivity;
import com.findtech.threePomelos.activity.BabyDataDetailActivity;
import com.findtech.threePomelos.bluetooth.BLEDevice;
import com.findtech.threePomelos.bluetooth.ReceivedataActivity;
import com.findtech.threePomelos.entity.TravelInfoEntity;
import com.findtech.threePomelos.login.LoginActivity;
import com.findtech.threePomelos.login.PhoneVerifyActivity;
import com.findtech.threePomelos.login.SetBabySexActivity;


public class MainActivity extends MyActionBarActivity implements Toolbar.OnMenuItemClickListener,
        View.OnClickListener, BLEDevice.RFStarBLEBroadcastReceiver {

    private Button skipButton;
    private Button userInfoButton;
    private Button mapInfoButton;
    private Button loginButton;
    private Button registerButton;
    private Button searchButton;
    private Button receiverButton;
    private LinearLayout imageView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        AVAnalytics.trackAppOpened(getIntent());
        startActivity(new Intent(this, LaunchActivity.class));

        setContentView(R.layout.activity_main);
        MyApplication.getInstance().addActivity(this);
        skipButton = (Button) findViewById(R.id.skip);
        mapInfoButton = (Button) findViewById(R.id.usermap);
        userInfoButton = (Button) findViewById(R.id.userinfo);
        loginButton = (Button) findViewById(R.id.login);
        registerButton = (Button) findViewById(R.id.register);
        searchButton = (Button) findViewById(R.id.search);
        receiverButton = (Button) findViewById(R.id.receiver);
        imageView = (LinearLayout) findViewById(R.id.image);
//        mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer);
        skipButton.setOnClickListener(this);
        userInfoButton.setOnClickListener(this);
        mapInfoButton.setOnClickListener(this);
        loginButton.setOnClickListener(this);
        registerButton.setOnClickListener(this);
        searchButton.setOnClickListener(this);
        receiverButton.setOnClickListener(this);
    }

    @Override
    public boolean onMenuItemClick(MenuItem menuItem) {
        return false;
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.skip:
                startActivity(new Intent(this, SetBabySexActivity.class));
                break;
            case R.id.userinfo:
                startActivity(new Intent(this, BabyDataDetailActivity.class));
                break;
            case R.id.usermap:
                startActivity(new Intent(this, HomeActivity.class));
                break;
            case R.id.login:
                startActivity(new Intent(this, LoginActivity.class));
                break;
            case R.id.register:
                startActivity(new Intent(this, PhoneVerifyActivity.class));
                break;
            case R.id.receiver:
                startActivity(new Intent(this, ReceivedataActivity.class));
                break;
            case R.id.search:
                break;
        }
    }


    @Override
    protected void onResume() {
        super.onResume();
        if (app.manager.cubicBLEDevice != null) {
            app.manager.cubicBLEDevice.setBLEBroadcastDelegate(this);
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
    }

    @Override
    public void onReceive(Context context, Intent intent, String macData, String uuid) {

    }

    @Override
    public void onReceiveDataAvailable(String dataType, String data, TravelInfoEntity travelInfoEntity, String time) {

    }
}
